#ifndef __BSP_PWM_H
#define __BSP_PWM_H

#include "User_App.h"

// 定义PWM输出管脚
#define MOTOR_IN1_GPIO TIM14, LL_TIM_CHANNEL_CH1 // 电机1
#define MOTOR_IN2_GPIO TIM16, LL_TIM_CHANNEL_CH1 // 电机2
#define MOTOR_IN3_GPIO TIM14, LL_TIM_CHANNEL_CH1 // 电机3
#define PWM_BEEP_GPIO TIM14, LL_TIM_CHANNEL_CH1  // 蜂鸣器

typedef enum
{
    p_STOP,
    p_RUN,
} pwm_t;

typedef struct
{
    TIM_TypeDef *p_TIMx;    // 选择的定时器  例如:TIM1
    uint32_t p_CHANNEL_CHx; // 选择的PWM通道 例如:LL_TIM_CHANNEL_CH1
    uint16_t p_PSC;         // 可编程预分频器
    uint16_t p_ARR;         // 自动重装载寄存器
} p_MCU_t;

typedef struct
{
    pwm_t p_State;    // 状态
    float p_Cycle_ms; // 周期
    float p_Hz;       // 频率
    float p_Pulse;    // 占空比 %
    p_MCU_t p_Mcu;
} PWM_t;

// extern PWM_t MOTOR_IN1;
// extern PWM_t MOTOR_IN2;

PWM_t bsp_PWM_Obj_New(TIM_TypeDef *tim, uint32_t Channel, float hz, float pulse, pwm_t state);
void bsp_PWM_Set_Pulse(PWM_t *obj, float value);
void bsp_PWM_Set_Run(PWM_t *obj);
void bsp_PWM_Set_Stop(PWM_t *obj);
pwm_t bsp_PWM_Get_State(PWM_t *obj);
void bsp_PWM_Debug(void);
void bsp_PWM_Set_Hz(PWM_t *obj, float value);

#endif
